from openphantasy.server.models import *

def delete_all(*a):
    for kls in a:
        for x in kls.objects.all():
            x.delete()

def reset():        
    eng=Country(code='ENG', name='England')
    eng.save()
    ita=Country(code='ITA', name='Italy')
    ita.save()
    
    leagues = (League(name='Premier', country=eng, level=1, numOfTeams=20, numPromoted=0, numRelegated=3),
               League(name='Championship', country=eng, level=2, numOfTeams=24, numPromoted=3, numRelegated=3),
               League(name='League 1', country=eng, level=3, numOfTeams=24, numPromoted=3, numRelegated=4),
               League(name='League 2', country=eng, level=4, numOfTeams=24, numPromoted=4, numRelegated=2),
               League(name='Conference', country=eng, level=5, numOfTeams=24, numPromoted=2, numRelegated=0)
               )
    for l in leagues: l.save()
    
    p = ['Arsenal', 
         'Aston Villa', 
         'Blackburn Rovers',
         'Bolton Wanderers',
         'Chelsea', 
         'Everton' , 
         'Fulham' ,
         'Hull City' , 
         'Liverpool' , 
         'Manchester City' , 
         'Manchester United' , 
         'Middlesbrough' , 
         'Newcastle United' , 
         'Portsmouth' , 
         'Stoke City' , 
         'Sunderland' , 
         'Tottenham Hotspur' , 
         'West Bromwich Albion' , 
         'West Ham United' , 
         'Wigan Athletic']
    for name in p:
        team = Team(name=name, country=eng, lastLeague=leagues[0])
        team.save()
        
    ch = """Barnsley | Birmingham City | Blackpool | Bristol City | Burnley | Cardiff City | Charlton Athletic | Coventry City | Crystal Palace | Derby County | Doncaster Rovers | Ipswich Town | Norwich City | Nottingham Forest | Plymouth Argyle | Preston North End | Queens Park Rangers | Reading | Sheffield United | Sheffield Wednesday | Southampton | Swansea City | Watford | Wolverhampton Wanderers""".split("|")
    for name in ch:
        team = Team(name=name.strip(), country=eng, lastLeague=leagues[1])
        team.save()
        
    l1 = """Brighton & Hove Albion | Bristol Rovers | Carlisle United | Cheltenham Town | Colchester United | Crewe Alexandra | Hartlepool United | Hereford United | Huddersfield Town | Leeds United | Leicester City | Leyton Orient | Millwall | Milton Keynes Dons | Northampton Town | Oldham Athletic | Peterborough United | Scunthorpe United | Southend United | Stockport County | Swindon Town | Tranmere Rovers | Walsall | Yeovil Town""".split("|")
    for name in l1:
        team = Team(name=name.strip(), country=eng, lastLeague=leagues[2])
        team.save()
        
    l2 = """Accrington Stanley | Aldershot Town | AFC Bournemouth | Barnet | Bradford City | Brentford | Bury | Chester City | Chesterfield | Dagenham & Redbridge | Darlington | Exeter City | Gillingham | Grimsby Town | Lincoln City | Luton Town | Macclesfield Town | Morecambe | Notts County | Port Vale | Rochdale | Rotherham United | Shrewsbury Town | Wycombe Wanderers""".split("|")
    for name in l2:
        team = Team(name=name.strip(), country=eng, lastLeague=leagues[3])
        team.save()
        
    con = """Altrincham | Barrow | Burton Albion | Cambridge United | Crawley Town | Eastbourne Borough | Ebbsfleet United | Forest Green Rovers | Grays Athletic | Histon | Kettering Town | Kidderminster Harriers | Lewes | Mansfield Town | Northwich Victoria | Oxford United | Rushden & Diamonds | Salisbury City | Stevenage Borough | Torquay United | Weymouth | Woking | Wrexham | York City""".split("|")
    for name in con:
        team = Team(name=name.strip(), country=eng, lastLeague=leagues[4])
        team.save()
        


    
def nuke():
    delete_all(Country, League, Team, Season, Round, Match)
    reset()
    